package com.mfp.java.testYou.core.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.log4j.Logger;

import com.mfp.java.testYou.core.AppContext;
import com.mfp.java.testYou.core.utils.UrlUtils;
import com.mfp.java.testYou.core.utils.Utils;

public class LoggingFilter implements Filter {

	private static final Logger log = Logger.getLogger(LoggingFilter.class);

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		log.info("Logging filter initialized");
	}

	@Override
	@SuppressWarnings("unchecked")
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		log.debug("Loading page: " + UrlUtils.getTarget(request));
		log.debug("Parameters:" + Utils.printMap(request.getParameterMap()));
		log.debug("User session: " + AppContext.getUserSession(request).toString());
		
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
	}
	
}
